function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
import "core-js/modules/es.symbol.js";
import "core-js/modules/es.symbol.description.js";
import "core-js/modules/es.symbol.iterator.js";
import "core-js/modules/es.symbol.to-primitive.js";
import "core-js/modules/es.array.filter.js";
import "core-js/modules/es.array.includes.js";
import "core-js/modules/es.array.iterator.js";
import "core-js/modules/es.date.to-primitive.js";
import "core-js/modules/es.map.js";
import "core-js/modules/es.number.constructor.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/es.string.includes.js";
import "core-js/modules/es.string.iterator.js";
import "core-js/modules/web.dom-collections.for-each.js";
import "core-js/modules/web.dom-collections.iterator.js";
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var EventBus = /*#__PURE__*/function () {
  function EventBus() {
    _classCallCheck(this, EventBus);
    _defineProperty(this, "eventMap", new Map());
  }
  return _createClass(EventBus, [{
    key: "subscribe",
    value: function subscribe(name, cb) {
      // 事件订阅
      if (typeof cb !== 'function') return;
      if (!this.eventMap.has(name)) this.eventMap.set(name, []);
      var eventList = this.eventMap.get(name);
      !eventList.includes(cb) && eventList.push(cb);
      this.eventMap.set(name, eventList);
    }
  }, {
    key: "publish",
    value: function publish(name) {
      var _this$eventMap$get;
      // 事件发布
      (_this$eventMap$get = this.eventMap.get(name)) === null || _this$eventMap$get === void 0 || _this$eventMap$get.forEach(function (cb) {
        return cb();
      });
    }
  }, {
    key: "cancel",
    value: function cancel(name, cb) {
      // 取消订阅
      if (this.eventMap.has(name)) {
        this.eventMap.set(name, this.eventMap.get(name).filter(function (i) {
          return i !== cb;
        }));
      }
    }
  }, {
    key: "clear",
    value: function clear(name) {
      // 清除订阅
      this.eventMap.delete(name);
    }
  }, {
    key: "clearAll",
    value: function clearAll() {
      // 清除所有订阅
      this.eventMap = new Map();
    }
  }], [{
    key: "getInstance",
    value: function getInstance() {
      if (!EventBus.eb) EventBus.eb = new EventBus();
      return EventBus.eb;
    }
  }]);
}();
export default EventBus.getInstance();
